package com.cyys.login.controller;

import com.cyys.login.back.Back;
import com.cyys.login.bo.LoginBo;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @author Administrator
 * @description LogginController
 * @date 2022-06-09 16:13
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @PostMapping
    public Back login (@RequestBody LoginBo loginBo) throws IOException {
        System.out.println(loginBo);
        String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + "wx7a54374e32c3ab51" + "&secret=" + "c4b51f78f005e929df3f2de392bf0cdf" + "&js_code=" + loginBo.getCode() + "&grant_type=authorization_code";
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder().url(url).build();
        Response response = client.newCall(request).execute();
        if (response.isSuccessful()) {
            String body = response.body().string();
            System.out.println(body);
        }


            return new Back();
    }

}
